<?php

/**
 * @author Samrat Khan - Apr 22, 2013
 */
    require('top.inc.php');
    $formLoad = new Form();
?>
<?php
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1 || $_SESSION['user']['utype'] == 2 || $_SESSION['user']['utype'] == 3 || $_SESSION['user']['utype'] == 4) {
    $sess_cusID = $_SESSION['user']['cus_id'];
    if(isset($_POST['addFaultyExport'])) {
        $query = "INSERT INTO faulty_export (serialno, project_id, productid, description, revisionstate, boxno, 
                uom, faulty_export_quantity, handedoverto, manufacturingdate, faultydocketnumber, docketdate, siteid, 
                warehouse_id, receivedfrom, rr_rma, export_rma, rr_invoiceno, rr_date, rr_mawb, rr_awb, remarks, userid, 
                cus_id, inserteddate)
             
            VALUES (:serialno, :project_id, :productid, :description, :revisionstate, :boxno, :uom, :faulty_export_quantity, 
            :handedoverto, :manufacturingdate, :faultydocketnumber, :docketdate, :siteid, :warehouse_id, :receivedfrom, 
            :rr_rma, :export_rma, :rr_invoiceno, :rr_date, :rr_mawb, :rr_awb, :remarks, :userid, :cus_id, :inserteddate)";
        
        //var_dump($query);
        
        $query_params = array(
            ':serialno'                 => $_POST['serialno'],
            ':project_id'               => $_POST['project_id'],
            ':productid'                => $_POST['productid'],
            ':description'              => $_POST['description'],
            ':revisionstate'            => $_POST['revisionstate'],
            ':boxno'                    => $_POST['boxno'],
            ':uom'                      => $_POST['uom'],
            ':faulty_export_quantity'   => $_POST['faulty_export_quantity'],
            ':handedoverto'             => $_POST['handedoverto'],
            ':manufacturingdate'        => $_POST['manufacturingdate'],
            ':faultydocketnumber'       => $_POST['faultydocketnumber'],
            ':docketdate'               => $_POST['docketdate'],
            ':siteid'                   => $_POST['siteid'],
            ':warehouse_id'             => $_POST['warehouse_id'],
            ':receivedfrom'             => $_POST['receivedfrom'],
            ':rr_rma'                   => $_POST['rr_rma'],
            ':export_rma'               => $_POST['export_rma'],
            ':rr_invoiceno'             => $_POST['rr_invoiceno'],
            ':rr_date'                  => $_POST['rr_date'],
            ':rr_mawb'                  => $_POST['rr_mawb'],
            ':rr_awb'                   => $_POST['rr_awb'],
            ':remarks'                  => $_POST['remarks'],
            ':userid'                   => $_POST['userid'],
            ':cus_id'                   => $_POST['cus_id'],
            ':inserteddate'             => date('Y-m-d H:i:s')
        );
        
        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        if($result) {
            echo $msg['4'];
        }
    } else {
?>
<div class="row-fluid" id="ShowResult"></div>
<form class="form-horizontal" action="" method="post" id="addFaultyExport">
    <div class="control-group">
        <label class="control-label" for="serialno"><?php echo $stock_in['serialno']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("serialno", "span2", "faulty_export_sn", $stock_in['serialno']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="project_id"><?php echo $projects['project_id']; ?></label>
        <div class="controls">
            <select name="project_id" id="project_id">
                <?php echo getProjects(cus_id, $sess_cusID, $db) ?>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="productid"><?php echo $faulty_export['productid']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("productid", "span2", "productid", $faulty_export['productid']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="description"><?php echo $faulty_export['description']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textArea("description", "span5", "description"); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="revisionstate"><?php echo $faulty_export['revisionstate']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("revisionstate", "span2", "revisionstate", $faulty_export['revisionstate']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="boxno"><?php echo $faulty_export['boxno']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("boxno", "span2", "boxno", $faulty_export['boxno']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="uom"><?php echo $uom['uom_id']; ?></label>
        <div class="controls">
            <select name="uom" id="uom">
                <?php echo getUOM($db); ?>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="faulty_export_quantity"><?php echo $faulty_export['faulty_export_quantity']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("faulty_export_quantity", "span2", "", $faulty_export['faulty_export_quantity']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="handedoverto"><?php echo $faulty_export['handedoverto']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("handedoverto", "span2", "", $faulty_export['handedoverto']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="manufacturingdate"><?php echo $faulty_export['manufacturingdate']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("manufacturingdate", "span2", "manufacturingdate", $faulty_export['manufacturingdate']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="faultydocketnumber"><?php echo $faulty_export['faultydocketnumber']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("faultydocketnumber", "span2", "", $faulty_export['faultydocketnumber']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="docketdate"><?php echo $faulty_export['docketdate']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("docketdate", "span2", "docketdate", $faulty_export['docketdate']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="siteid"><?php echo $faulty_export['siteid']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("siteid", "span2", "siteid", $faulty_export['siteid']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="warehouse_id"><?php echo $warehouses['warehouse_id']; ?></label>
        <div class="controls">
            <select name="warehouse_id" id="warehouse_id">
                <?php echo getWarehousesCode($db); ?>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="receivedfrom"><?php echo $faulty_export['receivedfrom']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("receivedfrom", "span2", "", $faulty_export['receivedfrom']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="rr_rma"><?php echo $faulty_export['rr_rma']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("rr_rma", "span2", "", $faulty_export['rr_rma']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="export_rma"><?php echo $faulty_export['export_rma']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("export_rma", "span2", "", $faulty_export['export_rma']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="rr_invoiceno"><?php echo $faulty_export['rr_invoiceno']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("rr_invoiceno", "span2", "", $faulty_export['rr_invoiceno']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="rr_date"><?php echo $faulty_export['rr_date']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("rr_date", "span2", "rr_date", $faulty_export['rr_date']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="rr_mawb"><?php echo $faulty_export['rr_mawb']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("rr_mawb", "span2", "", $faulty_export['rr_mawb']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="rr_awb"><?php echo $faulty_export['rr_awb']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("rr_awb", "span2", "", $faulty_export['rr_awb']); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="remarks"><?php echo $faulty_export['remarks']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textArea("remarks", "span5", "remarks"); ?>
        </div>
    </div>
       
    <input type="hidden" name="userid" value="<?php echo $_SESSION['user']['id']; ?>" />
    <input type="hidden" name="cus_id" value="<?php echo $_SESSION['user']['cus_id']; ?>" />
    
    <div class="control-group">
        <label class="control-label" for="inputEmail">&nbsp;</label>
        <div class="controls"><input class="btn btn-primary" type="submit" value="Add Item" name="addFaultyExport" /></div>
    </div>
    
    
    
</form>
<?php
    }
} else {
    header("Location: login.php");
}
?>
<?php
    include ('bottom.inc.php');
?>